package leecode

func majorityElement(nums []int) []int {
	numsMap := make(map[int]int, len(nums)) //key为数组中的元素,value为对应出现的次数
	for _, num := range nums {
		numsMap[num] = numsMap[num] + 1
	}
	tempMap := make(map[int]int, len(numsMap)) //中间的map集合
	result := make([]int, 0, len(numsMap))
	for _, num := range nums {
		if numsMap[num] > len(nums)/3 {
			tempMap[num] = tempMap[num] + 1
			if tempMap[num] == 1 {
				result = append(result, num)
			}
		}
	}
	//取出切片中的重复元素
	return result
}
